import Vue from 'vue'
import Vuex from 'vuex'
import menus from "./modules/menus";
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:sessionStorage.getItem("token")
  },
  mutations: {
    SET_TOKEN:(state,token)=>{

      state.token = token;
      localStorage.setItem("token",token);
    },
    REMOVE_INFO:(state)=>{

      state.token = '';
      state.userInfo = {} ;
      localStorage.setItem("token",'');
      localStorage.setItem("userInfo",JSON.stringify(''));

    },
    SET_USERINFO:(state,userInfo)=>{

      state.userInfo = userInfo;

      localStorage.setItem("userInfo",userInfo);
    },
  },
  getters:{

    getUser:state => {
      return state.userInfo;
    },
    getToken:state => {
      if (state.token == null){

        return '';
      }else
      return state.userInfo;
    }
  },
  actions: {
  },
  modules: {
    menus
  }
})
